package com.rq.adapter;

import android.view.View;
import android.widget.TextView;

import com.rq.rvlibrary.BaseAdapter;
import com.rq.rvlibrary.BaseViewHolder;
import com.rq.rvlibrary.ViewDataGetter;

public class KeepViewHolder extends BaseViewHolder implements ViewDataGetter {
    public KeepViewHolder(View itemView) {
        super(itemView);
    }

    @Override
    public int inflateLayoutId() {
        return R.layout.item_keep;
    }

    @Override
    public void fillData(BaseAdapter adapter, int position, Object o) {
        super.fillData(adapter, position, o);
        LOG.e("KeepViewHolder", position + ".23:" + getTextFromView(R.id.tv));
        TextView tv = (TextView) getItemView(R.id.tv);
        StringBuffer sb = new StringBuffer();
        if (tv.getTag() == null) {
            tv.setTag("" + position);
            sb.append(position + ">");
        } else {
            sb.append(tv.getTag());
            sb.append(".");
        }
        setItemText(R.id.tv, sb.toString());
        LOG.e("KeepViewHolder", position + ".28:" + getTextFromView(R.id.tv));

        LOG.e("KeepViewHolder", "fillData.removeItem:" + this);
    }

    @Override
    public Object getViewData() {
        return getTextFromView(R.id.tv) + ":" + getTextFromView(R.id.input);
    }

    @Override
    public Object[] beforeChange() {
        return new Object[]{getTextFromView(R.id.input)};
    }

    @Override
    public void afterChange(Object[] old, int position) {
        setItemText(R.id.input, String.valueOf(old[0]));
        LOG.e("KeepViewHolder", position + ".37:" + old[0]);
    }
}
